<?php

App::uses('AppController', 'Controller');

/**
 * 
 */
class ApisController extends AppController {

    var $name = "Apis";
    public $components = array('DebugKit.Toolbar');

    /**
     * This controller does not use a model
     *
     * @var array
     */
    public $uses = array('Users', 'Comments');

    public function beforeFilter() {
        parent::beforeFilter();
    }

    public function shareTwitter($message) {
        App::import('Vendor', 'Twitteroauth', array('file' => 'twitteroauth' . DS . 'twitteroauth.php'));
        $twitter_access_token = '761135143-upEhweGzgjTtOl200bfuzb4lYsZwcmjRWoHlYWUZ';
        $twitter_access_token_secret = 'rhHqUCVTqdalfoKH82BaAP3SbFJyiZISyfLcgiJYyEE';
        $twitter_consumer_key = Configure::read('Twitter.consumer_key');//'kiaHPGhENyvsBMSGBduK8w';
        $twitter_consumer_secret = Configure::read('Twitter.consumer_secret');//'CNcllIu9eSF83Zy4hhtLt704C6bBFYEQnlLlCmCGe4';
        // Connect to Twitter
        
        $connection = new TwitterOAuth($twitter_consumer_key, $twitter_consumer_secret, $twitter_access_token, $twitter_access_token_secret);

        // Post Update
        $content = $connection->post('statuses/update', array('status' => $message));
        $this->set('content', $content);
        $this->render('/Pages/home');
    }

    public function listAll() {
        $this->Users->set($this->request->query);
        if($this->Users->validates()){
            $this->set('content', $this->Users->find('all'));
        }else{
            $errors = $this->Users->validationErrors;
            $this->set('content', $errors);
        }
        
        $this->render('/Pages/home');
    }

    public function deleteUser($id) {
        $this->set('content', $this->Users->delete($id, true));
        $this->render('/Pages/home');
    }

    public function addUser() {
        $this->set('content', $this->Users->save(array('name' => 'Phu',
                    'email' => 'pisun2@gmail.com',
                    'username' => 'pisun2')));
        $this->render('/Pages/home');
    }

    public function addComment() {
        $this->set('content', $this->Comments->save(array('user_id' => '4',
                    'comments' => 'This is comment!')));
        $this->render('/Pages/home');
    }

}